<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>产品库存</title>
		<link rel="stylesheet" type="text/css" href="../css/proStockDetails.css" />
		<link type="text/css" href="../css/jquery-ui-1.8.17.custom.css" rel="stylesheet" />
		<link type="text/css" href="../css/jquery-ui-timepicker-addon.css" rel="stylesheet" />
		<script type="text/javascript" src="../js/jquery.min.js" charset="utf-8"></script>
		<script src="../js/deom.js" type="text/javascript" charset="utf-8"></script>
		<meta name="viewport" content=" height=device-height,
			          width=device-width,
			          initial-scale=1.0,
			          minimum-scale=1.0,
			          maximum-scale=1.0,
			          user-scalable=no" />
		<script src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js"></script>
		<script type="text/javascript" src="../js/jquery-1.7.1.min.js"></script>
		<script type="text/javascript" src="../js/jquery.event.drag-1.5.min.js"></script>
		<script type="text/javascript" src="../js/jquery.touchSlider.js"></script>
		<script type="text/javascript" src="../js/jquery-ui-1.8.17.custom.min.js"></script>
		<script type="text/javascript" src="../js/jquery-ui-timepicker-addon.js"></script>
		<script type="text/javascript" src="../js/jquery-ui-timepicker-zh-CN.js"></script>
		<script>
			$(document).ready(function() {
				$("#igs").touchSlider({
					paging: $(".flicking_con a"),
					counter: function(e) {
						$(".flicking_con a").removeClass("on").eq(e.current - 1).addClass("on");
					}
				});
			});
			$(function() {
				$(".ui_timepicker").datetimepicker({
					//showOn: "button",
					//buttonImage: "./css/images/icon_calendar.gif",
					//buttonImageOnly: true,
					showSecond: true,
					timeFormat: 'hh:mm:ss',
					stepHour: 1,
					stepMinute: 1,
					stepSecond: 1
				})
				//库存操作状态
				var stockState = "";
				//展示层
				function showLayer(id) {
					var initializationTime=(new Date()).getTime();
					var now=new Date();
					var year=now.getFullYear();
					var month=now.getMonth() + 1;
					var day=now.getDate();
					var hours=now.getHours();
                    var minutes=now.getMinutes();
                    var seconds=now.getSeconds();
                    var data = year+"-"+month+"-"+day+" "+hours+":"+minutes+":"+seconds;
                    document.getElementById('stockData').value = data;
					var layer = $('#' + id),
						layerwrap = layer.find('.hw-layer-wrap');
					layer.fadeIn();
					//屏幕居中
					layerwrap.css({
						'margin-top': -layerwrap.outerHeight() / 2
					});
				}

				//隐藏层
				function hideLayer() {
					$('.hw-overlay').fadeOut();
				}

				$('.hwLayer-cancel').on('click', function() {
					hideLayer();
				});
				$('#bot').on('click', function() {
					var urls = "";
					var stockNum = document.getElementById('stockNum').value;
					var stockData = document.getElementById('stockData').value;
					var userId = localStorage.getItem("userId");
					var proId = localStorage.getItem("proId");
					var token = localStorage.getItem("token");
					var ip = localStorage.getItem("ip");
					var scrap = document.getElementById('scrap').value;
					if('良品入库' == stockState) {
						urls = ip + "product/proStockInEdit";
					} else if('良品出库' == stockState) {
						urls = ip + "product/proStockOutEdit";
					} else if('不良品入库' == stockState) {
						urls = ip + "product/badproStockInEdit";
					} else if('不良品出库' == stockState) {
						urls = ip + "product/badproStockOutEdit";
					}
					$.ajax({
						type: 'post', //类型
						url: urls, //请求路径
						contentType: 'application/x-www-form-urlencoded', //默认
						dataType: 'json', //返回数据类型  可以是text：字符串  可以是json：json对象
						data: {
							'amount': stockNum,
							'truetime': stockData,
							'userId': userId,
							'pId': proId,
							'scrap': scrap,
							'token': token,
						}, //数据
						success: function(result) {
							if(result.code == 200) {
								window.location.href = 'proStockDetails.html';
							} else {
							}
						},
						error: function(data) { //若果传过来的数据为空
						}
					});
					$('.hw-overlay').fadeOut();
				});

				//触发弹出层良品入库
				$('#goodStorage').on('click', function() {
					var layerid = $(this).data('show-layer');
					stockState = "良品入库";
					$(".scrap").hide();
					document.getElementById('stocktit').innerText = stockState;
					showLayer(layerid);
				});
				//触发弹出层良品出库
				$('#goodLibrary').on('click', function() {
					var layerid = $(this).data('show-layer');
					stockState = "良品出库";
					$(".scrap").hide();
					document.getElementById('stocktit').innerText = stockState;
					showLayer(layerid);
				});
				//触发弹出层不良品入库
				$('#unhealthyStorage').on('click', function() {
					var layerid = $(this).data('show-layer');
					stockState = "不良品入库";
					$(".scrap").hide();
					document.getElementById('stocktit').innerText = stockState;
					showLayer(layerid);
				});
				//触发弹出层不良品出库
				$('#unhealthyLibrary').on('click', function() {
					var layerid = $(this).data('show-layer');
					stockState = "不良品出库";
					$(".scrap").show();
					document.getElementById('stocktit').innerText = stockState;
					showLayer(layerid);
				});

				//点击或者触控弹出层外的半透明遮罩层，关闭弹出层
				$('.hw-overlay').on('click', function(event) {
					if(event.target == this) {
						hideLayer();
					}
				});

				//按ESC键关闭弹出层
				$(document).keyup(function(event) {
					if(event.keyCode == 27) {
						hideLayer();
					}
				});

				//获取详情信息
				var userId = localStorage.getItem("userId");
				var proId = localStorage.getItem("proId");
				var token = localStorage.getItem("token");
				var ip = localStorage.getItem("ip");
				$.ajax({
					type: 'post', //类型
					//					url:'http://192.168.1.104:8080/wxs/wx/product/suppdetails',
					url: ip + 'product/suppdetails', //请求路径
					contentType: 'application/x-www-form-urlencoded', //默认
					dataType: 'json', //返回数据类型  可以是text：字符串  可以是json：json对象
					data: {
						'proId': proId,
						'userId': userId,
						'token': token,
					}, //数据
					success: function(result) {
						if(result.code == 200) {
							var txts = '';
							for(var Key in result.data.projectImgVo) {
								var imagePath =result.data.projectImgVo[Key].imagePath;
								if(imagePath == null){
									imagePath ='http://39.108.187.126:8080/nop.png';
								}
								txts = txts + '<a class="ig" onclick=' + 'getimgs('+'"'+imagePath+'"'+');>';
								txts = txts + '<img class="imgs" src="' + imagePath + '"/></a>';
							}
							$("#igs").append(txts);
							var protit = result.data.proName + result.data.proType + result.data.proModel;
							document.getElementById('title').value = protit;
							var proSellerNum = result.data.proSellerNum;
							document.getElementById('proSellerNum').innerText = proSellerNum;
							var proDescribe = result.data.proDescribe;
							document.getElementById('proDescribe').innerText = proDescribe;
							var stock = result.data.stock - result.data.unstock;
							document.getElementById('stock').innerText = stock;
							document.getElementById('totalInventory').innerText = result.data.stock;
							var unstock = result.data.unstock;
							document.getElementById('unstock').innerText = unstock;
							
						} else {
							alert('获取数据异常,请重新登录');
							//window.location.href = 'Login.html';
						}
					},
					error: function(data) { //若果传过来的数据为空
					}
				});
			});

			function getimgs(imagePath) {
				window.open(imagePath);
			}
		</script>
	</head>

	<body>
		<div id="igs">
		</div>
		<div class="btn btn1">
			<</div>
				<div class="btn btn2">></div>
				<textarea id="title" class="pro_tit" readonly="readonly" style="margin-top: 75%;">产品名称+产品类型+产品型号</textarea>
				<div class="pro_info">
					<label>产品编号:</label>
					<font id="proSellerNum">产品编号</font>
				</div>
				<div class="pro_info">
					<label>产品描述:</label>
					<font id="proDescribe">产品描述</font>
				</div>
				<div class="pro_info">
					<label>库存总数:</label>
					<font id="totalInventory">库存总数</font>
				</div>
				<div class="pro_info_stock">
					<label>良品库存:</label>
					<font id="stock">良品库存</font>
					<label style="margin-left:10%;">不良品库存:</label>
					<font id="unstock">不良品库存</font>
				</div>
				<div class="div-but">
					<input id="goodStorage" class="div-but-submit" data-show-layer="hw-layer" type="button" value="产品入库" />
					<input id="goodLibrary" class="div-but-submit" data-show-layer="hw-layer" type="button" value="良品出库" />
				</div>
				<div class="div-buts">
					<input id="unhealthyStorage" class="div-but-submit" data-show-layer="hw-layer" type="button" value="不良品入库" />
					<input id="unhealthyLibrary" class="div-but-submit" data-show-layer="hw-layer" type="button" value="不良品出库" />
				</div>
				<div class="hw-overlay" id="hw-layer">
					<div class="hw-layer-wrap">
						<tr valou>
							<font id="stocktit" style="color: #3d85c6;">入库出库</font><br><br>
							<td><input style="height: 35px;" id="stockNum" type="text" placeholder="请输数量" class="easyui-validatebox span3" data-options="required:true" value=""></td><br><br>
							<td><input style="height: 35px;" id="stockData" type="text" readonly="readonly" name="datetime" class="ui_timepicker" placeholder="请选择时间" value="""></td><br><br>
							<select id="scrap" class="scrap" style="height: 35px; width: 80%; -webkit-border-radius: 10px;display:none;">
								<option value="1">返工入库</option>
								<option value="0">报废处理</option>
							</select><br><br>
							<td><input class="hwLayer-cancel" type="button" id="bot" value="提交"  /></td>
							<td><input class="hwLayer-cancel" type="button" name="" id="" value="取消" style=" background: #F0F0F0;" /></td>
						</tr>
					</div>
				</div>
	</body>

</html>